#include "minunit.h"
#include <assert.h>
#include <string.h>
#include <lcthw/mystring.h>
char *test1 = "test1 data";
char *test2 = "test2 dataa";
char *test3 = "test3 dataa"; 
char *test[] = {"test1 data","test2 data","test3 data","test4 data","test5 data","test6 data"};

char *test_strlen()
{
    mu_assert(mystrlen(test1) == strlen(test1),"error!");
    return NULL;
}
char *test_strcpy()
{
    char dest1[100];
    char dest2[100];
    strcpy(dest1,test1);
    mystrcpy(dest2,test1);
    mu_assert(strcmp(dest1,dest2) == 0,"error!");
    return NULL;
}
char *test_strncpy()
{
    char dest1[100];
    char dest2[100];
    strncpy(dest1,test1,6);
    mystrncpy(dest2,test1,6);
    mu_assert(strcmp(dest1,dest2) == 0,"strncpy error!");
    return NULL;
}
char *test_strcat()
{
    char dest1[100] ="";
    char dest2[100] ="";
    
    strcat(dest1,test1);
    mystrcat(dest2,test1);
    mu_assert(strcmp(dest1,dest2) == 0,"strcat error!");
    strcat(dest1,test1);
    mystrcat(dest2,test1);
    mu_assert(strcmp(dest1,dest2) == 0,"strcat error!");
    return NULL;
}
char *test_strcmp()
{
    char dest1[100] ="";
    char dest2[100] ="";
    mu_assert(mystrcmp(dest1,dest2) == 0,"strcmp error!");  
    strncat(dest1,test1,4);
    mystrncat(dest2,test1,4);
    mu_assert(mystrcmp(dest1,dest2) == 0,"strcmp error!");
    puts(dest2);
    strcat(dest1,test1);
    mystrcat(dest2,test2);
    mu_assert(mystrcmp(dest1,dest2)  < 0,"strcmp error!");
    mu_assert(mystrcmp("dest11","dest1")  > 0,"strncmp error!");
    mu_assert(mystrncmp("dest11","dest1",0)  == 0,"strncmp error!");
    mu_assert(mystrncmp("dest11","dest1",1)  == 0,"strncmp error!");
    mu_assert(mystrncmp("dest11","dest1",6)  > 0,"strncmp error!");
    return NULL;
}
char *test_strncat()
{
    char dest1[100] ="";
    char dest2[100] ="";
    mu_assert(strcmp(dest1,dest2) == 0,"strncat error!");
    strncat(dest1,test1,1);
    mystrncat(dest2,test1,1);
    mu_assert(strcmp(dest1,dest2) == 0,"strncat error!");
    return NULL;
}
char *test_memset()
{
    char dest1[100] ="";
    char dest2[100] ="";
    memset(dest1,'a',1);
    mymemset(dest2,'a',1);
    mu_assert(strcmp(dest1,dest2) == 0,"mymemset error!");
    mu_assert(strcmp((char*)memset(dest1,'q',4),(char*)mymemset(dest2,'q',4)) == 0,"mymemset error!");
    return NULL;
}
char *test_memcpy()
{
    char src1[100] ="abcdefghijkl";
    char src3[100] ="abcdefghijkl";
    int  src2[100] ={1,2,3,4,5,100,213,12343245};
    char dest1[100] ="";
    char dest2[100] ="";  
  
    mymemcpy(dest1,src1,3) ;
    memcpy(dest2,src1,3) ;
    mu_assert(strcmp(dest1,dest2) == 0,"mymemcpy error!");
    mymemcpy(dest1,src2,3) ;
    memcpy(dest2,src2,3) ;
    mu_assert(strcmp(dest1,dest2) == 0,"mymemcpy error!");
    mymemcpy(src1,src1+2,3) ;
    memcpy(src3,src3+2,3) ;
    mu_assert(strcmp(src1,src3) == 0,"mymemcpy error!");
    mymemcpy(src1+2,src1,3) ;
    memcpy(src3+2,src3,3) ;
    mu_assert(strcmp(src1,src3) == 0,"mymemcpy error!");
        return NULL;
}
char *test_memmove()
{
    char src1[100] ="abcdefghijkl";
    char src3[100] ="abcdefghijkl";
    int  src2[100] ={1,2,3,4,5,100,213,12343245};
    char dest1[100] ="";
    char dest2[100] ="";    
    mymemmove(dest1,src1,3) ;
    memmove(dest2,src1,3) ;
    mu_assert(strcmp(dest1,dest2) == 0,"mymemmove error!");
    mymemmove(dest1,src2,3) ;
    memmove(dest2,src2,3) ;
    mu_assert(strcmp(dest1,dest2) == 0,"mymemmove error!");
    mymemmove(src1,src1+2,3) ;
    memmove(src3,src3+2,3) ;
    mu_assert(strcmp(src1,src3) == 0,"mymemmove error!");
    mymemmove(src1+2,src1,3) ;
    memmove(src3+2,src3,3) ;
    mu_assert(strcmp(src1,src3) == 0,"mymemmove error!");
        return NULL;
}

char *test_memcmp()
{
    int  src1[100] ={1,2,3,4,5,100,213,12343245};
    int  src2[100] ={1,2,0,4,5,100,213,12343245};
    mu_assert(mymemcmp("dest11","dest1",5)  == 0,"memcmp error!");
    mu_assert(mymemcmp("dest11","dest1",0)  == 0,"memcmp error!");
    mu_assert(mymemcmp("dest11","dest1",1)  == 0,"memcmp error!");
    mu_assert(mymemcmp("dest11","dest1",6)  >  0,"memcmp error!");
    mu_assert(mymemcmp(src1,src2,sizeof(int)*2)  ==  0,"memcmp error!");
    mu_assert(mymemcmp(src1,src2,sizeof(int)*3)  >  0,"memcmp error!");
    mu_assert(mymemcmp(src1,src2,sizeof(int)*5)  >  0,"memcmp error!");
    return NULL;
}
char *all_tests() {
    mu_suite_start();
    mu_run_test(test_strlen);
    mu_run_test(test_strcpy);
    mu_run_test(test_strncpy);
    mu_run_test(test_strcat);
    mu_run_test(test_strncat);
    mu_run_test(test_strcmp); //and strncmp

    mu_run_test(test_memset); 
    mu_run_test(test_memcpy); 
    mu_run_test(test_memmove); 
    mu_run_test(test_memcmp); 

    mystrcmp(test1,test2);
    puts(test1);
    return NULL;
}

RUN_TESTS(all_tests);